package com.qms.app.controller;

import com.qms.app.aop.SystemControllerLog;
import com.qms.app.bean.Question;
import com.qms.app.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @SystemControllerLog(description = "分页查询提问问题")
    @RequestMapping("/listQuestion")
    public Map<String,Object> listQuestion(Integer page, Integer rows , String title){
        Map<String,Object> map = new HashMap<>();
        map.put("total",questionService.countQuestion(title));
        map.put("rows",questionService.listQuestion(page,rows,title));
        return map;
    }

    @SystemControllerLog(description = "提问问题")
    @RequestMapping("/saveQuestion")
    public boolean saveQuestion(Question question){
        return questionService.save(question);
    }

    @SystemControllerLog(description = "删除提问问题")
    @RequestMapping("/removeQuestion")
    public boolean removeQuestion(@RequestParam("ids[]") List<Integer>  ids){
        return questionService.remove(ids);
    }

    @SystemControllerLog(description = "修改提问问题")
    @RequestMapping("/updateQuestion")
    public boolean updateQuestion(Question question){
        return questionService.update(question);
    }
}
